package MyMain;

public class MyMain {
    static boolean action = true;

    public static void main(String[] args) {
        Thread t1 = new Thread(){
            @Override
            public void run() {
                while (true){
                    if(action){
                        System.out.println("1");
                        action=false;
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        };


        Thread t2 = new Thread(){
            @Override
            public void run() {
                while (true){
                    if (!action){
                        System.out.println("2");
                        action = true;
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        };


        t1.start();
        t2.start();






    }
}
